#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, k, sum=0;
//const int N = 1e6;
//ll a[N];
bool check(ll num , vector<ll> &a)
{
	ll sum_imp = 0;
	for(ll i=1; i<=n; i++)
	{
		sum_imp += min(a[i], num);
	}	
	return sum_imp / k >= num;
}


int main()
{
	ios::sync_with_stdio(false);        //节省cout 和 cin 比 peintf 和 sacnf慢的时间
	cin >> n >> k;
	vector<ll> a(n+1);  //right+1可能会访问到a[n+1]
	for(ll i=1; i<=n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	
	
	ll left = 0, right = sum + 1;
	while(left + 1 < right)
	{
		ll mid = left + ( right - left ) / 2;
		if(check(mid, a))
			left = mid;
		else
			right = mid;
	}
	cout << left << endl;
	return 0;
}



